// 路由原信息
// 二级路由组件
// 当打包构建应用时，JavaScript 包会变得非常大，影响页面加载。
// 如果我们能把不同路由对应的组件分割成不同的代码块，然后当路由被访问的时候才加载对应组件，这样就会更加高效。
export default [{
        path: "/center",
        component: () =>
            import ('../pages/Center'),
        meta: { show: true },
        children: [{
                path: 'myorder',
                component: () =>
                    import ('../pages/Center/MyOrder')
            },
            {
                path: 'gtouporder',
                component: () =>
                    import ('../pages/Center/GtoupOrder')
            },
            {
                path: '/center',
                redirect: '/center/myorder'
            }
        ]
    }, {
        path: "/paysuccess",
        component: () =>
            import ('../pages/PaySuccess'),
        meta: { show: true },
    }, {
        path: "/pay",
        component: () =>
            import ('../pages/Pay'),
        meta: { show: true },
        beforeEnter: (to, from, next) => {
            // ...只能从交易页面跳转到支付页面
            if (from.path == '/trade') {
                next()
            } else {
                next(false)
            }
        }
    }, {
        path: "/trade",
        component: () =>
            import ('../pages/Trade'),
        meta: { show: true },
        beforeEnter: (to, from, next) => {
            // 路由独享守卫 只能从购物跳转到交易页面
            if (from.path == '/shopcart') {
                next()
            } else {
                next(false)
            }
        }
    },
    {
        path: "/shopcart",
        component: () =>
            import ('../pages/ShopCart'),
        meta: { show: true },
    }, {
        path: "/detail/:skuid",
        component: () =>
            import ('../pages/Detail'),
        meta: { show: true },
    }, {
        path: "/addcartsuccess",
        name: 'addcartsuccess',
        component: () =>
            import ('../pages/AddCartSuccess'),
        meta: { show: true },
    },
    {
        path: "/home",
        component: () =>
            import ('../pages/Home'),
        meta: { show: true },
    },
    {
        path: "/login",
        component: () =>
            import ('../pages/Login'),
        meta: { show: false },
    },
    {
        path: "/register",
        component: () =>
            import ('../pages/Register'),
        meta: { show: false },
    },
    {
        path: "/search/:keyword?",
        component: () =>
            import ('../pages/Search'),
        meta: { show: true },
        name: "search",
        // 路由组件能传props数据:
        // boolean写法只能传递params参数
        // props: true
        // 对象写法
        // props:{a:1,b:2}
        // 函数写法：可以写params参数和query参数
        // props: ($route) => {
        //     return { keyword: $route.params.keyword, k: $route.query.k }
        // }
    },
    //重定向，在项目跳起来时，访问/，立马让他定向首页
    {
        path: "*",
        redirect: "/home",
    },
]